package com.czy.moudle.service.impl;

import com.czy.moudle.service.ExtFileService;
import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by czyja on 2016/7/30.
 */
public class ExtFileServiceImpl implements ExtFileService {
    @Override
    public List<String> readExCludeField(String fileName) {
        if (StringUtils.isEmpty(fileName)) {
            throw new RuntimeException("配置文件路径不能为空");
        }

        File file = new File(fileName);
        if (!file.exists()) {
            throw new RuntimeException(fileName + "文件不存在！");
        }

        List<String> result = new ArrayList<>();

        try {
            Scanner scanner = new Scanner(file);

            while (scanner.hasNextLine()){
                result.add(scanner.nextLine());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        return result;
    }
}
